﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Converters;
using MobileSales.Server.Services;

namespace MobileSales.Server.RestServices
{
    [ServiceContract(Namespace = "RestCake")]
    public class Service : ServiceBase
    {
        [OperationContract]
        [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare,
                RequestFormat = WebMessageFormat.Json,
                UriTemplate = "Call",
                Method = "POST")]
        public Stream Unit(Model.Products.Unit unit)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.DefaultValueHandling = DefaultValueHandling.Ignore;
            settings.Converters.Add(new StringEnumConverter());

            JsonSerializer serializer = JsonSerializer.Create(settings);
            StringWriter writer = new StringWriter();

            Dictionary<string, MobileSales.Model.Params.ParamType> dict = new Dictionary<string, MobileSales.Model.Params.ParamType>();
            dict.Add("dziś", MobileSales.Model.Params.ParamType.Client);

            
            serializer.Serialize(writer, dict);
            return new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(writer.ToString()));
        }

        [OperationContract]
        [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare,
                RequestFormat = WebMessageFormat.Json,
                UriTemplate = "NotifyMe",
                Method = "POST")]
        public void NotifyMe()
        {
            int id = this.GetEmployeeIdFromToken();
            this.Notify(id, Util.ServiceType.AuthService, "Ty kurwa durniu", 666);
        }
    }
}
